<?php

namespace app\admin\controller\recruit;

use app\common\controller\Backend;
use fast\Tree;

/**
 * 会员规则管理
 *
 * @icon fa fa-circle-o
 */
class Post extends Backend
{

    /**
     * Ad模型对象
     */
    protected $model = null;
    protected $adlist = [];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Post');
        $this->rec_id=0;
    }

    /**
     * 查看
     */
    public function index()
    {
        $recruit_id = $this->request->param('ids');
//         dump($this->request->param());die;
        $this->view->assign('id',$recruit_id);//recruit_id
        $title=model('Recruit')->where('recruit_id', $recruit_id)->value('recruit_title');//recruit_id
        $this->view->assign('content',$title);
        
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name'))
            {
                return $this->selectpage();
            }
            
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model ->where($where)->where('recruit_id='.$recruit_id)->order($sort, $order)->count();
            $list = $this->model ->where($where)->where('recruit_id='.$recruit_id)->order($sort, $order)->limit($offset, $limit)->select();
            foreach($list as &$ad){
                $ad['recruit_id']=model('Recruit')->where('recruit_id', 'eq', $ad['recruit_id'])->value('recruit_title');
            }
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }
    /**
     * 添加
     */
    public function add()
    {
//        $this->view->assign('row',array());
//        $this->view->assign('loclist', build_select('row[ad_location]', \app\admin\model\AdLocation::column('location_id,location_name'), '', ['class' => 'form-control selectpicker']));
       return parent::add();
    }
    /**
     * 编辑
     */
    public function edit($ids = NULL)
    {
        $row = $this->model->get($ids);
        if (!$row){
            $this->error(__('No Results were found'));
        }
        return parent::edit($ids);
    }

    /**
     * 删除
     */
    public function del($ids = "")
    {
        if ($ids)
        {
            $delIds = array_unique(explode(',', $ids));
            $count = $this->model->where('post_id', 'in', $delIds)->delete();
            if ($count)
            {
                $this->success();
            }
        }
        $this->error();
    }

}
